package com.rickpan.dto.response;

import com.rickpan.entity.FriendGroup;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.Builder;

import java.time.LocalDateTime;

/**
 * 好友分组响应DTO
 */
@Data
@Builder
@Schema(description = "好友分组信息")
public class FriendGroupResponse {

    @Schema(description = "分组ID")
    private Long id;

    @Schema(description = "分组名称")
    private String groupName;

    @Schema(description = "分组描述")
    private String description;

    @Schema(description = "排序顺序")
    private Integer sortOrder;

    @Schema(description = "该分组下的好友数量")
    private Long friendCount;

    @Schema(description = "创建时间")
    private LocalDateTime createdAt;

    @Schema(description = "更新时间")
    private LocalDateTime updatedAt;

    /**
     * 从实体类转换为响应DTO
     */
    public static FriendGroupResponse from(FriendGroup friendGroup) {
        return FriendGroupResponse.builder()
                .id(friendGroup.getId())
                .groupName(friendGroup.getGroupName())
                .description(friendGroup.getDescription())
                .sortOrder(friendGroup.getSortOrder())
                .createdAt(friendGroup.getCreatedAt())
                .updatedAt(friendGroup.getUpdatedAt())
                .build();
    }

    /**
     * 从实体类转换为响应DTO（包含好友数量）
     */
    public static FriendGroupResponse from(FriendGroup friendGroup, Long friendCount) {
        FriendGroupResponse response = from(friendGroup);
        response.setFriendCount(friendCount);
        return response;
    }
}
